package cn.robot.board;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.tbruyelle.rxpermissions.RxPermissions;

import rx.Subscription;


public class MainActivity extends AppCompatActivity {


    private RxPermissions rxPermission;
    private Subscription  permissionSub;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        rxPermission = new RxPermissions(this);

        findViewById(R.id.btn_simple_board).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, SimpleBoardActivity.class));
            }
        });
        findViewById(R.id.btn_ble_conn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, BleConnectActivity.class));
            }
        });
    }

    @Override
    protected void onStart() {
        super.onStart();
        checkSDPermission();
    }

    private void checkSDPermission() {
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION
                    , Manifest.permission.ACCESS_FINE_LOCATION
                    , Manifest.permission.WRITE_EXTERNAL_STORAGE
                    , Manifest.permission.READ_EXTERNAL_STORAGE
                    , Manifest.permission.BLUETOOTH_CONNECT
                    , Manifest.permission.BLUETOOTH_SCAN}, 1);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
